<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" href="/favicon.ico">
    <link rel="stylesheet" href="/resources/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/resources/css/public.css" media="all" />
    <link rel="stylesheet" href="/resources/layui_ext/dtree/dtree.css" media="all" />
    <link rel="stylesheet" href="/resources/layui_ext/dtree/font/dtreefont.css" media="all" />
</head>
<body class="childrenBody">
<!-- 查询条件开始-->

<form class="layui-form">
    <blockquote class="layui-elem-quote quoteBox">
        <form class="layui-form" >
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" name="title" id="title" class="layui-input searchVal" placeholder="请输入权限名称" />
                </div>
                <div class="layui-input-inline">
                    <input type="text" name="percode" id="percode" class="layui-input searchVal" placeholder="请输入权限编码" />
                </div>
                <button type="button" class="layui-btn layui-btn-radius" lay-submit lay-filter="doSearch" shiro:hasPermission="permission:view"><span class="layui-icon layui-icon-search"></span>查询</button>
                <button type="reset" class="layui-btn layui-btn-warm layui-btn-radius"><span class="layui-icon layui-icon-refresh-1"></span>重置</button>
            </div>
        </form>
    </blockquote>
</form>
<!-- 查询条件结束-->


<!-- 数据表格开始 -->
<div>
    <table class="layui-hide" id="permissionTable" lay-filter="permissionTable"></table>
    <!-- 工具栏 -->
<!--    <div id="permissionToolBar" style="display: none;">
        <button type="button" lay-event="add" class="layui-btn layui-btn-sm"><span class="layui-icon layui-icon-add-1"></span>添加权限</button>
    </div>-->

    <div id="permissionRowBar" style="display: none;">
        <button type="button" lay-event="update" class="layui-btn layui-btn-sm layui-btn-radius"><span class="layui-icon layui-icon-edit"></span>更新</button>
        <button type="button" lay-event="delete" class="layui-btn layui-btn-sm layui-btn-danger layui-btn-radius"><span class="layui-icon layui-icon-delete"></span>删除</button>
    </div>
</div>
<!-- 数据表格结束 -->

<!-- 添加和修改的弹出层开始 -->

<!-- 添加和修改的弹出层结束 -->





<script type="text/javascript" src="/resources/layui/layui.js"></script>
<script type="text/javascript">

    var tableIns;
    layui.extend({
        dtree: '/resources/layui_ext/dtree/dtree'   // {/}的意思即代表采用自有路径，即不跟随 base 路径
    }).use(['jquery','form','table','layer','dtree'],function () {
        var $=layui.jquery;
        var form=layui.form;
        var table=layui.table;
        var layer=layui.layer;
        var dtree = layui.dtree;

        //渲染数据表格
        tableIns = table.render({
            elem: '#permissionTable'//绑定表格组件的id元素
            ,url:'/permission/permissionList'//数据发送的请求路径
            ,toolbar: '#permissionToolBar' //开启头部工具栏，并为其绑定左侧模板
            ,title: '权限数据表'
            ,height:'full-100'
            ,page: true
            ,cols: [ [
                {type: 'checkbox', fixed: 'left'}
                ,{field:'id', title:'ID',align:'center',width:150}
                ,{field:'pid', title:'父节点ID',align:'center',width:150}
                ,{field:'title', title:'权限名称',align:'center',width:200}
                ,{field:'percode', title:'权限编码',align:'center',width:300}
                ,{field:'available', title:'是否可用',align:'center',templet:function (d) {
                        return d.available == 1 ? "<font color='blue'>是</font>" :"<font color='red'>否</font>";
                    }}
                //,{field:'right', title:'操作',align:'center',toolbar:"#permissionRowBar",width:200}
            ] ]
            //回调函数
            ,done:function (res,curr,count) {
                // 判断当前页码是否大于1
                if(curr>1 && res.data.length == 0){
                    //当前页码-1
                    var pageValue = curr - 1;
                    tableIns.reload({
                        page:{curr:pageValue}// 修改页码
                    })
                }
            }
        });

        //监听表单提交事件（模糊查询）
        form.on("submit(doSearch)",function (data) {
            tableIns.reload({
                where:data.field,//条件参数
                page:{
                    curr:1 //当前页码
                }
            });
        });
    });

    /**
     * 其它页面刷新当前页面数据表格
     * @param id    节点id
     */
    function loadTableData(id) {
        tableIns.reload({
            where:{"id":id},
            page:{curr:1}
        })
    }
</script>
</body>
</html>